home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / ldb / ldb.c < prev    next >
C/C++ Source or Header  |  1992-05-25  |  4KB  |  162 lines

  1. /* $Header: ldb.c,v 1.15.2.2 92/05/25 15:31:15 ram Exp $ */
  2. /* Lisp kernel core debugger */
  3.  
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include <sys/file.h>
  7. #include <sys/param.h>
  8. #include <sys/stat.h>
  9.  
  10. #include "ldb.h"
  11. #include "lisp.h"
  12. #include "alloc.h"
  13. #include "vars.h"
  14. #include "globals.h"
  15. #include "os.h"
  16. #include "arch.h"
  17.  
  18. lispobj lisp_nil_reg = NIL;
  19. char *lisp_csp_reg, *lisp_bsp_reg;
  20.  
  21. static lispobj alloc_str_list(list)
  22. char *list[];
  23. {
  24.     lispobj result, newcons;
  25.     struct cons *ptr;
  26.  
  27.     if (*list == NULL)
  28.         result = NIL;
  29.     else {
  30.         result = newcons = alloc_cons(alloc_string(*list++), NIL);
  31.  
  32.         while (*list != NULL) {
  33.             ptr = (struct cons *)PTR(newcons);
  34.             newcons = alloc_cons(alloc_string(*list++), NIL);
  35.             ptr->cdr = newcons;
  36.         }
  37.     }
  38.  
  39.     return result;
  40. }
  41.  
  42.  
  43. main(argc, argv, envp)
  44. int argc;
  45. char *argv[];
  46. char *envp[];
  47. {
  48.     char *arg, **argptr;
  49.     char *core = NULL, *default_core;
  50.     boolean restore_state, monitor;
  51.  
  52.     number_stack_start = (char *)&monitor;
  53.  
  54.     define_var("nil", NIL, TRUE);
  55.     define_var("t", T, TRUE);
  56.     monitor = FALSE;
  57.  
  58.     argptr = argv;
  59.     while ((arg = *++argptr) != NULL) {
  60.         if (strcmp(arg, "-core") == 0) {
  61.             if (core != NULL) {
  62.                 fprintf(stderr, "can only specify one core file.\n");
  63.                 exit(1);
  64.             }
  65.             core = *++argptr;
  66.             if (core == NULL) {
  67.                 fprintf(stderr, "-core must be followed by the name of the core file to use.\n");
  68.                 exit(1);
  69.             }
  70.         }
  71.     else if (strcmp(arg, "-monitor") == 0) {
  72.         monitor = TRUE;
  73.     }
  74.     }
  75.  
  76.     default_core = arch_init();
  77.     if (default_core == NULL)
  78.     default_core = "lisp.core";
  79.  
  80.     /* Note: the /usr/misc/.cmucl/lib/ default path is also wired into */
  81.     /* the lisp code in .../code/save.lisp. */
  82.  
  83.     if (core == NULL) {
  84.     static char buf[MAXPATHLEN];
  85.     extern char *getenv();
  86.     char *lib = getenv("CMUCLLIB");
  87.  
  88.     if (lib != NULL) {
  89.         char *dst;
  90.         struct stat statbuf;
  91.  
  92.         do {
  93.         dst = buf;
  94.         while (*lib != '\0' && *lib != ':')
  95.             *dst++ = *lib++;
  96.         if (dst != buf && dst[-1] != '/')
  97.             *dst++ = '/';
  98.         strcpy(dst, default_core);
  99.         if (stat(buf, &statbuf) == 0) {
  100.             core = buf;
  101.             break;
  102.         }
  103.         } while (*lib++ == ':');
  104.     }
  105.     if (core == NULL) {
  106.         strcpy(buf, "/usr/misc/.cmucl/lib/");
  107.         strcat(buf, default_core);
  108.         core = buf;
  109.     }
  110.     }
  111.  
  112.     os_init();
  113.  
  114. #if defined(EXT_PAGER)
  115.     pager_init();
  116. #endif
  117.  
  118.     gc_init();
  119.     
  120.     validate();
  121.  
  122.     globals_init();
  123.  
  124.     restore_state = load_core_file(core);
  125.  
  126. #ifdef ibmrt
  127.     if (!restore_state) {
  128.     SetSymbolValue(BINDING_STACK_POINTER, (lispobj)binding_stack);
  129.     SetSymbolValue(INTERNAL_GC_TRIGGER, fixnum(-1));
  130.     }
  131. #endif
  132.  
  133.     interrupt_init();
  134.  
  135.     arch_install_interrupt_handlers();
  136.     os_install_interrupt_handlers();
  137.  
  138.     /* Convert the argv and envp to something Lisp can grok. */
  139.     SetSymbolValue(LISP_COMMAND_LINE_LIST, alloc_str_list(argv));
  140.     SetSymbolValue(LISP_ENVIRONMENT_LIST, alloc_str_list(envp));
  141.  
  142. #ifndef mips
  143.     /* Turn on pseudo atomic for when we call into lisp. */
  144.     SetSymbolValue(PSEUDO_ATOMIC_ATOMIC, fixnum(1));
  145.     SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED, fixnum(0));
  146. #endif
  147.  
  148.     /* Snag a few of the signal */
  149.     test_init();
  150.  
  151.     if (!monitor) {
  152.     if (restore_state)
  153.             restore();
  154.     else
  155.         call_into_lisp(INITIAL_FUNCTION, SymbolFunction(INITIAL_FUNCTION),
  156.                current_control_stack_pointer, 0);
  157.     printf("%INITIAL-FUNCTION returned?");
  158.     }
  159.     while (1)
  160.     ldb_monitor();
  161. }
  162.